package com.xzq.erp.controller;


import com.xzq.erp.aspect.ApiOperationLog;
import com.xzq.erp.domain.dto.CategoryDTO;
import com.xzq.erp.domain.vo.CategoryTreeVO;
import com.xzq.erp.domain.vo.CategoryVO;
import com.xzq.erp.service.IProductCategoryService;
import com.xzq.erp.utils.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品分类表 前端控制器
 * </p>
 *
 * @author xzq
 * @since 2025-05-26
 */
@RestController
@RequestMapping("/product-category")
@Tag(name = "商品分类接口")
@RequiredArgsConstructor
public class ProductCategoryController {

    private final IProductCategoryService productCategoryService;

    @GetMapping
    @Operation(summary = "商品分类列表")
    @ApiOperationLog(description = "商品分类列表")
    public Response<List<CategoryVO>> getProductCategoryList() {
        return Response.success(productCategoryService.getProductCategoryList());
    }

    @GetMapping("/tree")
    @Operation(summary = "商品分类树")
    @ApiOperationLog(description = "商品分类树")
    public Response<List<CategoryTreeVO>> getProductCategoryTree() {
        return Response.success(productCategoryService.getProductCategoryTree());
    }

    @PostMapping
    @Operation(summary = "添加商品分类")
    @ApiOperationLog(description = "添加商品分类")
    public Response<Void> addProductCategory(@RequestBody @Validated CategoryDTO categoryDTO) {
        productCategoryService.addProductCategory(categoryDTO);
        return Response.success();
    }

    @PutMapping
    @Operation(summary = "修改商品分类")
    @ApiOperationLog(description = "修改商品分类")
    public Response<Void> updateProductCategory(@RequestBody @Validated CategoryDTO categoryDTO) {
        productCategoryService.updateProductCategory(categoryDTO);
        return Response.success();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除商品分类")
    @ApiOperationLog(description = "删除商品分类")
    public Response<Void> deleteProductCategory(@PathVariable Long id) {
        productCategoryService.deleteProductCategory(id);
        return Response.success();
    }

    @PutMapping("/{id}/status/{status}")
    @Operation(summary = "修改商品分类状态")
    @ApiOperationLog(description = "修改商品分类状态")
    public Response<Void> updateProductCategoryStatus(@PathVariable Long id, @PathVariable Integer status) {
        productCategoryService.updateProductStatus(id, status);
        return Response.success();
    }
}
